﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Liang.UI.Tools;


namespace Liang.UI
{
    public partial class FrmDetail : Form
    {
        private Object[] objects { get; set; }

        private string name { get; set; }

        private ListView listViewSource { get; set; }

        public FrmDetail()
        {
            InitializeComponent();
        }


        public FrmDetail(string name, ListView listview, params Object[] objects)
        {
            InitializeComponent();            
            this.name = name;
            this.listViewSource = listview;
            this.objects = objects;
        }

        /// <summary>
        /// 复制数据
        /// </summary>
        private  void MoveItem()
        {
            foreach (ListViewItem item in listViewSource.Items)
            {
                listViewSource.Items.Remove(item);
                listViewData.Items.Add(item);
            }
        }


        private void FrmDetail_Load(object sender, EventArgs e)
        {
            this.Text = name;//窗体描述名称
            //添加表头
            foreach (var obj in objects)
            {
                //ColumnHeader head = new ColumnHeader();
                //head.Text = obj.ToString();
                //head.Width = -2;
                //listViewData.Columns.Add(head);
                listViewData.Columns.Add(obj.ToString(), 120, HorizontalAlignment.Center);
            }
            MoveItem();
        }

        private void btnExcel_Click(object sender, EventArgs e)
        {
            FormHelper.ExpListViewExcel(this.listViewData,name);
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
